/**
 * 添加或修改员工信息
 * 
 * @param {}
 *            adminId
 * @return {}
 */
var addPriAdminWin = function(adminId) {
	var addPriAdminField = new Ext.form.FieldSet({
				collapsible : false,
				buttonAlign : 'center',
				layout : 'form',
				labelWidth : 55,
				buttons : [{
					text : "保存",
					width : 80,
					id : 'priAdminSave',
					handler : function() {
						var b = Ext.getCmp("addPriAdminForm");
						if (b.getForm().isValid()) {
							b.getForm().submit({
								url : __ctxPath
										+ "/systemAdmin/insertOrUpdateAdmin",
								method : "post",
								waitTitle : "请稍候",
								waitMsg : "正在提交表单，请稍候......",
								success : function(c, d) {
									Ext.MessageBox.show({
												title : "操作信息",
												msg : "保存信息成功!",
												buttons : Ext.MessageBox.OK,
												icon : Ext.MessageBox.INFO
											});
									addPriAdminWindow.close();
									queryPriAdmins();
								},
								failure : function(c, d) {
									Ext.MessageBox.show({
												title : "操作信息",
												msg : '保存信息失败!',
												buttons : Ext.MessageBox.OK,
												icon : Ext.MessageBox.ERROR
											});
								}
							});
						}
					}
				}, {
					text : "取消",
					width : 80,
					handler : function() {
						addPriAdminWindow.close();
					}
				}],
				items : [
						{
							xtype : "hidden",
							name : "id",
							anchor : '100%',
							value : adminId == null ? "" : adminId
						},
						{
							xtype : "hidden",
							id : 'addPriAdmin_deptId',
							anchor : '100%',
							name : "deptId"
						},
						{
							xtype : "hidden",
							id : 'addPriAdmin_postId',
							anchor : '100%',
							name : "postId"
						},
						{
							xtype : "textfield",
							id : 'addPriAdmin_name',
							allowBlank : false,
							blankText : "登录名不能为空...",
							name : "name",
							anchor : '100%',
							fieldLabel : "登录名",
							listeners : {
								'blur' : function() {
									var adminName = Ext
											.getCmp("addPriAdmin_name")
											.getValue();
									queryAdminNameExist(adminName);
								}
							}

						},
						{
							xtype : "textfield",
							name : "trueName",
							anchor : '100%',
							allowBlank : false,
							fieldLabel : "姓名"
						},{
							xtype : "combo",
							mode : "local",
							fieldLabel : "性别",
							anchor : '100%',
							hiddenName : "sex",
							emptyText : "选择状态",
							store : new Ext.data.ArrayStore({
										fields : ["value", "text"],
										data : [[1, "男"], [0, "女"]]
									}),
							valueField : "value",
							displayField : "text",
							triggerAction : "all",
							value:1,
							editable : false
						},{
							xtype : "textfield",
							inputType : "password",
							allowBlank : false,
							id : 'addPriAdmin_pass',
							blankText : "密码不能为空...",
							anchor : '100%',
							name : "pass",
							fieldLabel : "密    码"
						},
						new TreeSelector(
								"addPriAdmin_treeDeptSelector",
								__ctxPath
										+ "/systemDept/selectDeptTreeById?deptRoot="
										+ curUserInfo.deptId, "所属部门",
								"addPriAdmin_deptId", false, 240), {
							xtype : "textfield",
							vtype : "email",
							anchor : '100%',
							name : "email",
							fieldLabel : "邮   箱"
						}, {
							xtype : "combo",
							mode : "local",
							fieldLabel : "状态",
							anchor : '100%',
							hiddenName : "isUseable",
							emptyText : "选择状态",
							store : new Ext.data.ArrayStore({
										fields : ["value", "text"],
										data : [[1, "可用"], [0, "禁用"]]
									}),
							valueField : "value",
							displayField : "text",
							triggerAction : "all",
							editable : false
						}, {
							id : 'addPriAdmin_treePostSelector',
							xtype : 'trigger',
							fieldLabel : "所属岗位",
							blankText : '请选择岗位',
							allowBlank : false,
							triggerClass : 'x-form-search-trigger',
							anchor : '100%',
							editable : false,
							onTriggerClick : function() {
								var url = __ctxPath
										+ "/systemPost/selectPostTree";
								var val = Ext.getCmp('addPriAdmin_postId')
										.getValue();
								postSelectTree(url, val).show();
							}
						}]
			});
	var addPriAdminForm = new Ext.form.FormPanel({
				id : 'addPriAdminForm',
				frame : true,
				buttonAlign : 'center',
				labelAlign : 'right',
				border : false,
				reader : new Ext.data.JsonReader({
							success : 'success',
							root : 'data'
						}, [{
									name : 'id'
								}, {
									name : 'deptId'
								}, {
									name : 'name'
								}, {
									name : 'trueName'
								}, {
									name : 'pass'
								}, {
									name : 'email'
								}, {
									name : 'isUseable'
								}, {
									name : 'postId'
								}, {
									name : 'deptName'
								}, {
									name : 'postName'
								}]),
				items : [addPriAdminField]
			});
	if (adminId != null && typeof(adminId) != "undefined") {
		Ext.getCmp("addPriAdmin_pass").disable().clearInvalid();
		addPriAdminForm.load({
			url : __ctxPath + "/systemAdmin/selectAdminById?adminId=" + adminId,
			root : "data",
			success : function(f, a) {
				var deptName = a.result.data.deptName;
				var postName = a.result.data.postName;
				Ext.getCmp("addPriAdmin_treeDeptSelector").setValue(deptName);
				Ext.getCmp("addPriAdmin_treePostSelector").setValue(postName);
			},
			failure : function(form, action) {
				Ext.MessageBox.show({
							title : "操作信息",
							msg : '数据加载失败!',
							buttons : Ext.MessageBox.OK,
							icon : Ext.MessageBox.ERROR
						});
			}
		});
	}

	var addPriAdminWindow = new Ext.Window({
				id : 'addPriAdminWindow',
				closeAction : 'close',
				title : '人员信息',
				modal : true,
				width : 350,
				height : 340,
				plain : true,
				layout : 'fit',
				items : [addPriAdminForm]
			});
	return addPriAdminWindow;
}
// 查看登录名是否存在
function queryAdminNameExist(adminName) {
	Ext.Ajax.request({
				url : __ctxPath + "/systemAdmin/selectAdminNameExist",
				method : "POST",
				params : {
					adminName : adminName
				},
				success : function(response, options) {
					var jsonData = Ext.util.JSON.decode(response.responseText);
					if (jsonData.success == 'false') {
						Ext.Msg.show({
									title : '提示',
									msg : jsonData.data,
									buttons : Ext.Msg.OK,
									icon : Ext.MessageBox.INFO
								});
						Ext.getCmp("addPriAdmin_name").setValue("");
					}
				},
				failure : function(response, options) {
				}
			});
}
